package com.sayice.gomoku.filter;

import javax.servlet.*;
import java.io.IOException;

/**
 * 用户登录检查
 */
public class UserFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("进入UserFilter");
        Object user = servletRequest.getAttribute("user");
        if (user == null) {
            servletRequest.getRequestDispatcher("/pages/user/login.jsp").forward(servletRequest, servletResponse);
            System.out.println("转发至登录页面");
        } else {
            filterChain.doFilter(servletRequest, servletResponse);
        }
    }
}
